package no.sachmuld.methodcombination.examples.reflection.designbycontract.courier;

import no.sachmuld.methodcombination.api.Condition;
import no.sachmuld.methodcombination.api.MethodCombinationSupport;
import no.sachmuld.methodcombination.api.reflection.DesignByContract;
import no.sachmuld.methodcombination.api.Context;
import no.sachmuld.methodcombination.api.MethodInvocation;

import java.lang.*;

/**
 *
 */
public class Courier extends MethodCombinationSupport<CourierBehaviour> {

    public Courier() {

        with(new CourierBehaviour() {

            @Override
            public Condition beforeDeliver(Package pkg, Context context) {
                return new Condition("package weight < 3", pkg.getWeightInKg() < 3);
            }

            @Override
            public Delivery deliver(Package pkg, MethodInvocation<Delivery> methodInvocation) {
                return new Delivery(6);
            }

            @Override
            public Condition afterDeliver(Package pkg, Delivery delivery, Context context) {
                return new Condition("delivery time < 8", delivery.getDeliveryTimeInHours() < 8);
            }

        });
    }

    public final Delivery deliver(final Package pkg) {
        return new DesignByContract<Delivery>().build(CourierBehaviour.class, Courier.class, "deliver", Package.class).execute(this, chain(), pkg);
    }
}
